//
//  BK_My_Cup_Used_tabVCell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/2/22.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_My_Cup_Used_tabVCell.h"
#import "Masonry.h"
#import "BK_my_couponCommon.h"
#import "BKMyCommon.h"
@interface BK_My_Cup_Used_tabVCell ()

@property (nonatomic, strong) UIImageView *greenImg;
@property (nonatomic, strong) UIImageView *whiteImg;
@property (nonatomic, strong) UILabel *moneyAmountLabel;//优惠劵金额
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *dataLabel;
@property (nonatomic, strong) UIImageView *daysRemainingImg;
@property (nonatomic, strong) UIView *view_bg;
@property (nonatomic, strong) UILabel *accessLabel;//使用商品
@property (nonatomic, strong) UILabel *lifeSpanLabel;//使用期限

@end

@implementation BK_My_Cup_Used_tabVCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initlizeSubViews];
    }
    return self;
}

- (void)initlizeSubViews {
    __weak typeof(self) weakSelf = self;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    
    /*
     * 打底的View
     */
    _view_bg = [[UIView alloc] init];
    _view_bg.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    [self.contentView addSubview:_view_bg];
    [_view_bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(0);
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(0);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).offset(-10);
    }];
    
    /*
     * 左边绿色图片
     */
    _greenImg = [[UIImageView alloc] init];
    [self.view_bg addSubview:_greenImg];
    [_greenImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view_bg.mas_top).offset(0);
        make.left.mas_equalTo(weakSelf.view_bg.mas_left).offset(0);
        make.width.mas_equalTo(100);
        make.bottom.mas_equalTo(weakSelf.view_bg.mas_bottom).offset(-1);
    }];
    
    _moneyAmountLabel = [[UILabel alloc] init];
    _moneyAmountLabel.textColor = [UIColor whiteColor];
    _moneyAmountLabel.font = [UIFont systemFontOfSize:30];
    _moneyAmountLabel.textAlignment = NSTextAlignmentCenter;
    [self.greenImg addSubview:_moneyAmountLabel];
    
    /*
     * 右边白色图片
     */
    _whiteImg = [[UIImageView alloc] init];
    [self.view_bg addSubview:_whiteImg];
    [_whiteImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view_bg.mas_top).offset(0);
        make.left.mas_equalTo(weakSelf.greenImg.mas_right).offset(0);
        make.right.mas_equalTo(weakSelf.view_bg.mas_right).offset(-ApplicationBackGauge);
        make.bottom.mas_equalTo(weakSelf.view_bg.mas_bottom).offset(-1);
    }];
    
    if ([UIScreen mainScreen].currentMode.size.width < 750) {
        _greenImg.image = [UIImage imageNamed:@"BK_my_couponGreenBG"];
        
        _whiteImg.image = [UIImage imageNamed:@"BK_my_couponWhiteBG"];
        
        [_moneyAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(weakSelf.greenImg.mas_centerX).offset(0);
            make.centerY.mas_equalTo(weakSelf.greenImg.mas_centerY).offset(0);
            make.width.mas_equalTo(100);
        }];
    } else {
        _greenImg.image = [UIImage imageNamed:@"BK_my_couponGreenBG"];
        
        _whiteImg.image = [UIImage imageNamed:@"BK_my_couponWhiteBG"];
        
        [_moneyAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(weakSelf.greenImg.mas_centerX).offset(0);
            make.centerY.mas_equalTo(weakSelf.greenImg.mas_centerY).offset(0);
            make.width.mas_equalTo(111);
        }];
    }
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:13];
    _titleLabel.textColor = BK_MY_COLOR_04;
    _titleLabel.numberOfLines = 2;
    [self.whiteImg addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.whiteImg.mas_left).offset(20);
        make.right.mas_equalTo(weakSelf.whiteImg.mas_right).offset(-10);
        make.top.mas_equalTo(weakSelf.whiteImg.mas_top).offset(15);
    }];
    
    _dataLabel = [[UILabel alloc] init];
    _dataLabel.font = [UIFont systemFontOfSize:10];
    _dataLabel.textColor = BK_MY_COLOR_04;
    [_dataLabel sizeToFit];
    [self.whiteImg addSubview:_dataLabel];
    [_dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.whiteImg.mas_left).offset(20);
        make.bottom.mas_equalTo(weakSelf.whiteImg.mas_bottom).offset(-10);
    }];
    
    _daysRemainingImg = [[UIImageView alloc] init];
    _daysRemainingImg.image = [UIImage imageNamed:@"BK_my_couponOrangeBG"];
    _daysRemainingImg.contentMode = UIViewContentModeScaleAspectFit;
    [self.whiteImg addSubview:_daysRemainingImg];
    [_daysRemainingImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.whiteImg.mas_bottom).offset(-10.5);
        make.left.mas_equalTo(weakSelf.dataLabel.mas_right).offset(1);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(15);
    }];
    
    _accessLabel = [[UILabel alloc] init];
    _accessLabel.textColor = RGBCOLOR(39, 201, 175, 1);
    _accessLabel.font = [UIFont systemFontOfSize:10];
    [self.whiteImg addSubview:_accessLabel];
    [_accessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.whiteImg.mas_left).offset(20);
        make.bottom.mas_equalTo(weakSelf.dataLabel.mas_top).offset(-5);
    }];
    
    _lifeSpanLabel = [[UILabel alloc] init];
    _lifeSpanLabel.textColor = [UIColor whiteColor];
    _lifeSpanLabel.font = [UIFont systemFontOfSize:10];
    _lifeSpanLabel.textAlignment = NSTextAlignmentCenter;
    [self.daysRemainingImg addSubview:_lifeSpanLabel];
    [_lifeSpanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.daysRemainingImg.mas_top).offset(2);
        make.left.mas_equalTo(weakSelf.daysRemainingImg.mas_left).offset(9);
    }];
}

- (void)setUnUsedModel:(BK_my_CouponModel *)unUsedModel {
    _unUsedModel = unUsedModel;
    NSString *string = [NSString stringWithFormat:@"￥%@", _unUsedModel.reduceCost];
    
    NSMutableAttributedString *muAtt = [[NSMutableAttributedString alloc] initWithString:string];
    [muAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, 1)];
    // NSRange range = [string rangeOfString:@"."];
    [muAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(string.length - 3, 3)];
    
    _moneyAmountLabel.attributedText = muAtt;
    _titleLabel.text = [NSString stringWithFormat:@"%@", _unUsedModel.couponTypeStr];
    _dataLabel.text = [NSString stringWithFormat:@"%@", _unUsedModel.invalidTimeStr];
    
    if (_unUsedModel.sprticific == 0) {
        _accessLabel.text = @"";
    } else if (_unUsedModel.sprticific == 1) {
        _accessLabel.text = [NSString stringWithFormat:@"%@", _unUsedModel.viewGoodsInfoStr];
    } else if (_unUsedModel.sprticific == 2) {
        _accessLabel.text = [NSString stringWithFormat:@"%@", _unUsedModel.viewCategoryInfoStr];
    }
    if ([unUsedModel.remainingWarning isEqualToString:@""]) {
        _daysRemainingImg.hidden = YES;
    } else {
        _daysRemainingImg.hidden = NO;
        self.lifeSpanLabel.text = [NSString stringWithFormat:@"%@", _unUsedModel.remainingWarning];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

